<!-- eslint-disable vue/multi-word-component-names -->
<template>
  <!-- 全部问题 -->
	<div>
		<h3 class="notitle">当前页面：{{ $route.meta.title }}</h3>
		<div id="table">
          <!-- <div class="pb10px">
            
            <el-input v-model="searchForm.problemDescription" class="input1" clearable placeholder="请输入问题描述"
                      size="small" ></el-input>
            <el-button type="primary" icon="el-icon-search" size="small" class="mr10px" @click="handleSearch">搜索</el-button>
          </div> -->
      
          
          <el-table
              ref="multipleTable"
              :data="tableData"
              tooltip-effect="dark"
              style="width: 100%"
              @selection-change="handleSelectionChange">
            <el-table-column
                type="selection"
                width="55"
                align="center">
            </el-table-column>
            <el-table-column
                prop="id"
                label="ID"
                width="100"
                align="center">
            </el-table-column>
            <el-table-column
                prop="name"
                label="项目名称"
                width="200"
                >
            </el-table-column>
            <el-table-column
                prop="problemDescription"
                label="问题描述"
                width="100"
                align="center"
                >
              <template v-slot="scope">
                <el-button @click="show(scope.row)" size="mini">显示内容</el-button>
              </template>
            </el-table-column>
			      <el-table-column
                prop="evaluate"
                label="评价"
                width="100"
                align="center">
            </el-table-column>
            <el-table-column
                prop="state"
                label="状态"
                width="100"
                align="center">
            </el-table-column>
			      <el-table-column
                prop="createDate"
                label="提出时间"
                width="200"
                align="center">
            </el-table-column>
			      <el-table-column
                prop="updateTime"
                label="更新时间"
                width="200"
                align="center">
            </el-table-column>
			
            <!-- fixed="right"-->
            <el-table-column label="操作"
                             width="350"
                             align="center">
              <template slot-scope="scope">
               
                <el-button
                  size="mini"
                  type="warning"
                  @click="handle(scope.$index, scope.row)">修改状态
                </el-button>
                <el-tooltip class="item" effect="dark" content="查看处理方案" placement="top">
                <el-button
                  size="mini"
                  type="primary"
                  @click="to(scope.row)">处理
                </el-button>
              </el-tooltip>
                <!-- <el-button
                    size="mini"
                    type="danger"
                    @click="handleDelete(scope.$index, scope.row)">删除
                </el-button> -->
                <el-tooltip class="item" effect="dark" content="下载客户上传文件" placement="top">
                <el-button
                  size="mini"
                  type="success"
                  @click="handleex(scope.$index, scope.row)">客户文件
                </el-button>
              </el-tooltip>
              </template>
            </el-table-column>
          </el-table>
      
          <!--自定义分页组件-->
          <custom-pages
              @current-change="currentChange"
              @size-change="sizeChange"
              :total="pageInfo.total"
              :page-size="pageInfo.pageSize"
              :current-page="pageInfo.pageNum"
              class="custom-pages"
          >
          </custom-pages>
          <!--自定义分页组件-->
        

          <!-- 自定义抽屉组件-->
          <custom-drawer
              :form-data="formData"
              :rules-form="ruleForm"
              @close-drawer="closeDrawer"
              @submit-drawer="submitDrawer"
              :is-drawer-dialog="isDrawerDialog"
          >
            <div slot="content">
              <el-form-item label="评价" prop="evaluate" v-if="judge1=='2'">
                <el-input v-model="formData.evaluate" placeholder="请输入评价"></el-input>
              </el-form-item>

              <el-form-item label="状态" prop="state" v-if="judge1=='1'" >
              <el-select v-model="formData.state" placeholder="请选择状态" >
                <el-option
                  v-for="item in  options"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value">
                </el-option>
              </el-select>
              </el-form-item>

            </div>
          </custom-drawer>
          <!--自定义抽屉组件 -->
    
          <el-dialog
            title="提示"
            :visible.sync="error"
            width="30%"
            append-to-body
            top="20%"
            ><!-- append-to-body出现不会屏幕变暗,top位置下调 -->
            <span>{{ message }}</span>
            <span slot="footer" class="dialog-footer">
                <el-button @click="error = false">取 消</el-button>
                <el-button type="primary" @click="error = false">确 定</el-button>
            </span>
            </el-dialog>
            
            <el-dialog
              title="问题的具体内容"
              :visible.sync="text"
              top="10%"
            >
              <el-card>
                <div style="font-size: 16px;">{{ content }}</div>
              </el-card>
              <div slot="footer" class="dialog-footer">
                
                <el-button type="primary" @click="text=false">确 定</el-button>
              </div>
            </el-dialog>

        </div>
		
	</div>
  </template>
   
  <script>
  

  import create from "@/mixins/create";
  import http from "@/utils/request.js"
  export default {
	
	data() {
	  return {
		api: {
              pageUrl: "/solve/getproblem",
              saveUrl: "/home/updateproblemevaluate",
              delUrl: "/home/deleteproblem",
              modUrl: "/home/updateproblemstate",
              search:"/solve/selectproblem",
            },
            ruleForm: {
			      evaluate: [
                {required: true, message: '请输入评价', trigger: 'blur'},
              ],
              state: [
                {required: true, message: '请输入状态', trigger: 'blur'},
              ],
            },
      
            formData: {
              id: null,
              evaluate: "", //评价
              state: "", //状态
            },
            searchForm: {
              problemDescription: ""
            },
            message:'',
            options: [{
              value: '待处理',
              label: '待处理'
            }, {
              value: '处理中',
              label: '处理中'
            }, {
              value: '已处理',
              label: '已处理'
            },],
            value: '',
            text:false,
            content:'',
	  };
	},
	mixins: [create],
    created() {
    },
	methods: {
    show(row){
          this.content=row.problemDescription//绑定数据
          this.text=true
    },
    //跳转页面
    to(row){
      sessionStorage.setItem('userId2',row.userId)
      sessionStorage.setItem('problemId',row.id)
      sessionStorage.setItem('text',row.problemDescription)
      sessionStorage.setItem('name',row.name)
      this.$router.push('/SloveView')
    },
	  handleex(index, row){
          if(row.url !='文件url'){
            let url=row.url;
            let link = document.createElement('a');
            link.href=url;
            link.target = '_self';
            link.style.display='none';
            // document.body.appendChild(link);
            link.click()
            // document.body.remove(link);
          }
          else{
            this.message='暂无文件'
            this.error = true
          }
          
    },

    getList() {
            let formData = {
                //当前页
                pageNum: this.pageInfo.pageNum,
                //分页大小
                pageSize:this.pageInfo.pageSize,
                //总条数
                total: this.pageInfo.total,
                //角色id
                roleId:JSON.parse(sessionStorage.getItem('role')),
                userId:JSON.parse(sessionStorage.getItem('userId')),
            };
            let data = Object.assign(this.searchForm, this.pageInfo)
            http.get(`${this.api.pageUrl}?${new URLSearchParams(formData).toString()}`).then(res => {
              if(res.data.code=='200'){
                this.tableData = res.data.data.records
                this.pageInfo.total = res.data.data.total//动态获取分页
                console.log(res)
              }
              else{
                this.message='您还没有客户';
                this.error=true
              }
                
            })
        },
	  //修改状态   
	  handle(index, row) {
            sessionStorage.setItem('judge',1)
            this.updateMyVar()
            // console.log(this.judge1)//
            this.isDrawerDialog = true
            // console.log(index, row);
            this.formData = Object.assign({}, row)
        },
	  submitDrawer(e) {
            //修改状态
            if(sessionStorage.getItem('judge') == '1'){
                const params = new URLSearchParams();
                params.append('state', this.formData.state);
                params.append('problemId', this.formData.id);
                http.put(`${this.api.modUrl}?${params.toString()}`).then(res => {
                    // console.log(res)
                    if (res.data.code == 200) {
                        this.isDrawerDialog = false
                        this.$message({
                            message: res.data.msg,
                            type: 'success'
                        });
                        this.getList()
                    }
                    else {
                        this.message=res.data.msg,
                        this.error=true,
                        // this.$message({
                        //     message: res.data.msg,
                        //     type: 'error'
                        // });
                        this.getList()
                    }
                })
            }
            //评价问题
            else if(sessionStorage.getItem('judge') == '2'){
                const params1 = new URLSearchParams();
                params1.append('evaluate', this.formData.evaluate);
                params1.append('problemId', this.formData.id);
                http.put(`${this.api.saveUrl}?${params1.toString()}`).then(res => {
                    // console.log(res)
                    if (res.data.code == 200) {
                        this.isDrawerDialog = false
                        this.$message({
                            message: res.data.msg,
                            type: 'success'
                        });
                        this.getList()
                    }
                    else{
                        this.message=res.data.msg;
                        this.error=true;
                        // this.$message({
                        //       message: res.data.msg,
                        //       type: 'error'
                        //   });
                      }
                })
            }
        },
		    //单个删除
        handleDelete(index, row) {
            // console.log(index, row);
            this.ids = [row.id]
            // this.batchDelete()
            const id =this.ids[0];
            let formData1 = {
                problemId: id,//
            };
            //
            this.$confirm(`此操作将永久删除ID为[${this.ids[0]}]的数据, 是否继续?`, '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning',
                center: true
            }).then(() => {
                http.delete(`${this.api.delUrl}?${new URLSearchParams(formData1).toString()}`).then(res => {
                    // console.log(res)
                    if (res.data.code == 200) {
                        this.$message({
                            message: res.data.msg,
                            type: 'success'
                        });
                        this.getList()
                    }
                    else{
                        this.message=res.data.msg;
                        this.error=true;
                    }
                })
            }).catch(() => {
                // this.message=res.data.msg,
                // this.error=true,
                this.$message({
                    type: 'info',
                    message: '已取消删除'
                });
                this.$refs.multipleTable.clearSelection();
            });
        },
        //搜索
        handleSearch() {
            let formData1={
                
                //当前页
                pageNum: this.pageInfo.pageNum,
                //分页大小
                pageSize:this.pageInfo.pageSize,
                userId:sessionStorage.getItem('userId'),
                name:this.searchForm.problemDescription
            }
            
            http.get(`${this.api.search}?${new URLSearchParams(formData1).toString()}`).then(res => {
                    // console.log(res)
                    if (res.data.code == 200) {
                        console.log(res)
                        this.message=res.data.msg,
                        this.error=true,
                        //更换表格数据
                        this.tableData = res.data.data.records
                        this.pageInfo.total = res.data.data.total//动态获取分页
                    }
                    else {
                        this.message=res.data.msg,
                        this.error=true,
                        this.getList()
                    }
                })
        },
	},

	
  };
  </script>
  <style scoped>
	
  .notitle{
    color: black;
    font-size:25px;
    margin-top: 1%; 
    margin-left: 0%;
  }/* 面包屑 */

  #title{
	font-size:25px;/*字体大小 */
    text-align: center;/*位置居中 */
	margin-top: 5px;
	margin-bottom: 5px;
  }	

  .input1{
    width: 260px;
  }
  .custom-pages {
      position: absolute;
      /* position: relative; */
      top: 100%;
      /* 设置其始终位于页面底部 */
    }
  </style>
  